﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Configuration;

namespace WebService1
{
    /// <summary>
    /// Summary description for Service1
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class Service1 : System.Web.Services.WebService
    {

        [Serializable]
        public class CityData
        {
            public string CityName { get; set; }
            public double Latitude { get; set; }
            public double Longitude { get; set; }

            public CityData ()
	        {

	        }

            public CityData(string cityName, double nLatitude, double nLongitude)
            {
                CityName = cityName;
                Latitude = nLatitude;
                Longitude = nLongitude;
            }

        }


        [WebMethod]
        public List<CityData> GetCityData(string country)
        {

            using (DataClasses1DataContext ctx = new DataClasses1DataContext())
            {
                List<CityData> data = ctx.CityDatas.Where(f => f.Country.ToLower().Trim() == country.ToLower().Trim())
                                        .Select(f => new CityData(f.CityName,f.Latitude ?? 0,f.Longitude ?? 0)).ToList();
                return data;
            }

        }
    }
}
